<%@ page pageEncoding="UTF-8"%>
<script type="text/x-template" id="add_tag">
    <div class="_edit_tag">
        <div class="_pop-container">
            <div class="_top">
                新建扩展标签
            </div>
            <div class="_content">
                <div class="_each-content">
                    <span class="_title">名称: </span>
                    <input class="_input" type="text" v-model="editName">
                </div>
                <div class="_each-content">
                    <span class="_title">备注: </span>
                    <textarea class="_input" type="text" v-model="editRemark"></textarea>
                </div>
                <div class="_each-content">
                    <span class="_title"></span>
                    <div class="_submit-container">
                        <div class="_submit" @click="submit()" v-html="submitText">确定</div>
                    </div>
                </div>
            </div>
            <img class="_close" src="/images/components/add_member/ic-close.png" alt="" @click="closeAddMember()">
        </div>
    </div>
</script>
<link rel="stylesheet" href="/css/components/edit_tag.css"/>
<script>
    var HOSPITAL = "${user.hospital}";
    var addTag = {
        template: "#add_tag",
        data: function() {
            return {
                editName: "",
                editRemark: "",
                submitText: "确定",
            }
        },
        methods: {
            closeAddMember: function() {
                this.$dispatch("closeAddTagShow");
            },
            submit: function() {
                var _this = this;
                var editName = this.editName.trim();
                var editRemark = this.editRemark.trim();
                if (editName.length == 0) {
                    this.$dispatch("danger", "请输入标签名称");
                    return;
                }
                if (!/^.{2,10}$/.test(editName)) {
                    this.$dispatch("danger", "标签名为2-10位");
                    return;
                }
                if (editRemark.length > 50) {
                    this.$dispatch("danger", "备注不得超过50个字");
                    return;
                }
                this.submitText = "请等待...";
                $.ajax({
                    type: 'POST',
                    url: "tag_manage.jsp",
                    data: {
                        act: "tagAdd",
                        hospital: HOSPITAL,
                        tag_name: editName,
                        tag_alias: editRemark,
                    },
                    success: function(res) {
                        _this.submitText = "确定";
                        res = JSON.parse(res);
                        if (res.errcode == 0) {
                            _this.$dispatch("message", "标签添加成功")
                            _this.$dispatch("addTagSuccess");
                        } else {
                            _this.$dispatch("danger", res.errmsg);
                        }
                    },
                });
            }
        },
        ready: function() {

        },
        components: {

        }
    }
</script>
